<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="static/easyui/locale/easyui-lang-zh_CN.js"></script>
<link rel="stylesheet" href="static/easyui/themes/metro-gray/easyui.css"/>
<link rel="stylesheet" href="static/easyui/themes/icon.css"/>
<title>处方开药</title>
</head>
<body> 
<script type="text/javascript">

//时间转换
function comformatDate(date) {
	var day = new Date(date); 
	var Year = 0; 
	var Month = 0; 
	var Day = 0; 
	var CurrentDate = ""; 
	//初始化时间 
	Year= day.getFullYear();//
	Month= day.getMonth()+1; 
	Day = day.getDate(); 
	Hour = day.getHours(); 
	 Minute = day.getMinutes(); 
	 Second = day.getSeconds(); 
	CurrentDate += Year + "-"; 
	if (Month >= 10 ) { 
		CurrentDate += Month + "-"; 
	}else { 
		CurrentDate += "0" + Month + "-"; 
	} 
	if (Day >= 10 ) { 
		CurrentDate += Day ; 
	}else { 
		CurrentDate += "0" + Day ; 
	} 
	if(Hour>=10){
		CurrentDate +=" "+Hour;
	}else{
		CurrentDate +=" "+"0"+Hour;
	}
	if(Minute>=10){
		CurrentDate +=":"+Minute;
	}else{
		CurrentDate +=":"+"0"+Minute;
	}
	if(Second>=10){
		CurrentDate +=":"+Second;
	}else{
		CurrentDate +=":"+"0"+Second;
	}
	return CurrentDate; 
};

$(function(){
	//访问数据源、初始化表格
	$('#yprufang').datagrid({
		url:'rukusy',
		onLoadSuccess: function (data) {
            if (data.total == 0) {
                //添加一个新数据行，第一列的值为你需要的提示信息，然后将其他列合并到第一列来，注意修改colspan参数为你columns配置的总列数
                $(this).datagrid('appendRow', { rkid: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'rkid', colspan: 7 })
                //隐藏分页导航条，这个需要熟悉datagrid的html结构，直接用jquery操作DOM对象，easyui datagrid没有提供相关方法隐藏导航条
                $(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide();
            }
            //如果通过调用reload方法重新加载数据有数据时显示出分页导航容器
            else $(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
        },
		columns:[[
					{field:'rkid',title:'入库编号',width:100,align:'right'},
					{field:'sqid',title:'申请编号',width:100,align:'right'},
					{field:'rktime',title:'新增时间',width:100,align:'right',formatter:comformatDate},
					{field:'jbr',title:'经办人',width:100,align:'right'},
					{field:'rksl',title:'总数量',width:100,align:'right'},
					{field:'rklb',title:'药品种类',width:100,align:'right'},
					{field:'cz',title:'操作*',width:200,
						formatter:function(value,row,index){
							return "<input type='button' style='background:#E4F1FB;color:#2779AA;border:none' onclick='rukuxq("+row.rkid+")' value='详情'/>";
						}	
					}
				]]

				
		});
	
	//名字查询
	$('#shijiancx').searchbox({
		searcher:function(value){
		    alert(value);
		    	   $('#yprufang').datagrid({
	    				url:'sjcx',
	    				queryParams:{
	    					nameq:value
	    				},
	    				onLoadSuccess: function (data) {
	    		            if (data.total == 0) {
	    		                //添加一个新数据行，第一列的值为你需要的提示信息，然后将其他列合并到第一列来，注意修改colspan参数为你columns配置的总列数
	    		                $(this).datagrid('appendRow', { rkid: '<div style="text-align:center;color:red">没有相关记录！</div>' }).datagrid('mergeCells', { index: 0, field: 'rkid', colspan: 7 })
	    		                //隐藏分页导航条，这个需要熟悉datagrid的html结构，直接用jquery操作DOM对象，easyui datagrid没有提供相关方法隐藏导航条
	    		                $(this).closest('div.datagrid-wrap').find('div.datagrid-pager').hide();
	    		            }
	    		            //如果通过调用reload方法重新加载数据有数据时显示出分页导航容器
	    		            else $(this).closest('div.datagrid-wrap').find('div.datagrid-pager').show();
	    		        },
	    				columns:[[
	    					{field:'rkid',title:'入库编号',width:100},
	    					{field:'rktime',title:'新增时间',width:100,formatter:comformatDate},
	    					{field:'jbr',title:'经办人',width:100,align:'right'},
	    					{field:'rksl',title:'总数量',width:100,align:'right'},
	    					{field:'rklb',title:'药品种类',width:100,align:'right'},
	    					{field:'cz',title:'操作*',width:200,
	    						formatter:function(value,row,index){
	    							return "<input type='button' style='background:#E4F1FB;color:#2779AA;border:none' onclick='rukuxq("+row.rkid+")' value='详情'/>";
	    						}	
	    					}
	    						]]
						});
		    }
		    
		  
	});
	
	
	//点击处方发药按钮
	$("#yzyruku").click(function(){
		$("<form method='post'>").appendTo("body").form({
			url:'ypxzjl',
			onSubmit:function (param){
				//时间
				param["order.addDate"] = new Date();
				//经办人
				param["order.addJbr"] = "颜梓毅";
				//是否同意
				param["order.addCz"] = "1";
				//获取表格中的采购的详情记录
				var rows = $("#syyp").datagrid("getRows");
				console.log(rows);
				
				for (var i = 0; i < rows.length; i++) {
					//药品编号
					param["details["+i+"].drugsYk.drugId"] = rows[i]["ypid"];
					//保质期
					param["details["+i+"].bzq"] = new Date();
					//药品批次
					param["details["+i+"].drugPc"] = rows[i]["yppc"];
					//时间
					param["details["+i+"].drugTime"] = new Date();
					//支出数量
					param["details["+i+"].drugs_number_xz"] =rows[i]["ypsl"]; 
					alert("处方id"+param["details["+i+"].goodAdd.addId"] );
				}
			},
			success:function(d){
				$.messager.show({
					title:'结果',
					msg:d,
					height:200,
					timeout:1000,
					showType:'slide'
				});
			}
		}).submit();
	});
})
	function rukuxq(a){
		$("#xzyp").window("open");
		//访问数据源、初始化表格
		$('#syyp').datagrid({
			url:'rukusyyp',
			queryParams:{
				sqid:a
			},
			columns:[[
						{field:'sqid',title:'入库编号',width:100},
						{field:'ypid',title:'药品编号',width:100},
						{field:'ypname',title:'药品名称',width:100},
						{field:'bzq',title:'保质期',width:100,align:'right'},
						{field:'ypsl',title:'总数量',width:100,align:'right'},
						{field:'yppc',title:'批次',width:100,align:'right'},
						{field:'ypdj',title:'价格',width:100,align:'right'}
					]]	
			});
	}
</script>
	<div class="easyui-panel" data-options="fit:true">
		<div>
		<p>
	时间查询：<input id="shijiancx" class="easyui-searchbox">
	</p>
			<table id="yprufang" class="easyui-datagrid" data-options="fitColumns:true,pagination:true"  style="height:400px">
				
		</table>
		</div>
	</div>
	<div id="xzyp" class="easyui-window" data-options="closed:true" title="入库详情">
			<table id="syyp" class="easyui-datagrid" data-options="fitColumns:true,pagination:true"  style="height:400px" width="500px">
				 
		</table>
		<a id="yzyruku" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true">入库</a>
	</div>
</body>
</html>